// c_base.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
double sign(double x);
int switch_test();
void min3();
void rev2equation();
void sum100();
void sum1_fact();
void factor_n();
void cal_pi();
void checkPrimeNumber(int num);
void maxCommonDivisor();
void maxCommonDivisor_sub();
void int_sinx();
void int_sinx_ori();
void fibonacci();
void sqrt_loop();
void seekSum12();
void transToCap();
void sumBang();
void X_seq();
int makeTestDataFile();
void reverseSequence();
void bubbleSeq();
void bubbleSeq2();
void chooseSeq();
void initCharArry();
void stringIO();
void copyString();
void lenString();
void copyString2();
void minLenString();
void catString();
void catString2();
void testTOLower_TOUpper();
void genMatrix();
void matrixTransposition();
void studentScore();
void twoDimensionCharArry();
void tongJiTouPiao();
void tongJiZhengShu();
void randomAndSortedArry();
void matrixMult();
void searchMatrix();
void stringCompare();
void containString();
void sortString();
void weekGen();
void sumDiag_2();
void mean5();
void array30_delMax();
int foo(int x);
float foo(float x);
void drawHexagon();
void testArgs(int *p);
void func(char str[]);
void showDayOfYear();
void add();
int day_of_year(int d_tab[][13], int year, int month, int day);

#define printt(x, y, z) printf("x=%d,y=%d,z=%d\n", x, y, z);
#define d_size 128 * 1024 * 1024





void add1();
void inc2();
int facto(int n);
double px(double x, int n);
void printn(int n);


int x=0,y=0;
int i=0;
void movedisc(unsigned n, char fromneedle, char toneedle, char usingneedle);
void swap2(int *px, int *py);
int *max(int *a, int *b);

int main()
{
	
	int a,b, *pa, *pb;
	a=5;
	b=10;
	printf("before swap a=%d,b=%d\n",a,b);
	swap2(&a,&b);
	printf("after swap a=%d,b=%d\n",a,b);
	
	int *pmax;
	pmax = max(&a,&b);
	printf("max=%d\n",*pmax);
	
	

	getchar();
	return 0;
}
//符号函数
double sign(double x)
{
	return x > 0 ? 1 : (x == 0 ? 0 : -1);
}
//分支语句
int switch_test()
{
	int x;
	printf("Please iput x:\n");
	scanf_s("%d", &x);
	switch (x / 10)
	{
	case 10: //printf("x=%d->A\n", x); break;
	case 9:
		printf("x=%d->A\n", x);
		break;
	case 8:
		printf("x=%d->B\n", x);
		break;
	case 7: //printf("x=%d->C\n", x); break;
	case 6:
		printf("x=%d->C\n", x);
		break;
	case 5: //printf("x=%d->D\n", x); break;
	case 4: //printf("x=%d->D\n", x); break;
	case 3: //printf("x=%d->D\n", x); break;
	case 2: //printf("x=%d->D\n", x); break;
	case 1: //printf("x=%d->D\n", x); break;
	case 0:
		printf("x=%d->D\n", x);
		break;
	default:
		printf("x=%d data error\n", x);
	}
	return 0;
}
//最小值
void min3()
{
	int a, b, c, min;
	printf("Please input a,b,c\n");
	scanf_s("%d,%d,%d", &a, &b, &c);
	min = a < b ? a : b;
	min = min < c ? min : c;
	printf("min=%d\n", min);
}
//二元一次方程求解，包括一次方程
void rev2equation()
{
	float a, b, c, a2, x1, x2;
	double d;

	printf("Input a,b,c\n");
	scanf_s("%f,%f,%f", &a, &b, &c);
	//一次方程
	if (a == 0)
		x1 = -c / b;
	else
	{
		d = b * b - 4 * a * c;
		a2 = 2 * a;
		x1 = -b / a2;

		if (d >= 0)
			x2 = sqrt(d) / a2;
		else
			x2 = sqrt(-d) / a2;
	}

	if (a == 0)
		printf("root=%f\n", x1);
	else
	{
		if (d >= 0) //实根
		{
			printf("real root:\n");
			printf("root1=%f,root2=%f\n", x1 + x2, x1 - x2);
		}
		else
		{
			printf("complex root:\n");
			printf("root1=%f +%fi\n", x1, x2);
			printf("root2=%f -%fi\n", x1, x2);
		}
	}
}
//1到100求和
void sum100()
{
	int s, i;
	s = 0;
	i = 1;
	while (i <= 100)
	{
		s += i;
		i++;
	}
	printf("1+2+3+……+100=%d\n", s);
}
//调和数列求和
void sum1_fact()
{
	int i;
	float s;
	s = 0;
	i = 1;
	while (i <= 100)
	{
		s += 1.0 / i;
		i++;
	}
	printf("1+1/2+1/3+……+1/100=%f\n", s);
}
//阶乘计算
void factor_n()
{
	int i, n;
	long s;
	s = 1;
	i = 1;
	printf("Please input n:\n");
	scanf_s("%d", &n);
	do
	{
		s *= i;
		i++;

	} while (i <= n);
	printf("%d!=%ld\n", n, s);
}
//pi值近似计算
// pi/4=1-1/3+1/5-1/7+...
void cal_pi()
{
	int i, k;
	float s;
	s = 0;
	k = 1;
	i = 1;
	do
	{
		s += k * 1.0 / i;
		i += 2;
		k = -k;

	} while (1.0 / i >= 1.e-4);
	s = 4 * s;
	printf("pai=%f\n", s);
}

//检测素数
void checkPrimeNumber(int num)
{
	int i, k, n;
	k = num;
	//scanf_s("%d", &k);
	n = 1;
	for (i = 2; i < k; i++)
	{
		if (k % i == 0)
		{
			n = 0;
			i = k;
		}
	}
	if (n == 1)
		printf("%d is a prime\n", k);
	else
		printf("%d is not a prime\n", k);
	printf("\n");
}
//最大公约数--辗转相除法
void maxCommonDivisor()
{
	int x, y, a, b, t;
	scanf_s("%d,%d", &x, &y);
	a = x;
	b = y;
	t = a % b;
	while (t != 0)
	{
		a = b;
		b = t;
		t = a % b;
	}
	printf("x=%d,y=%d->%d,%d\n", x, y, b, x * y / b);
}
//最大公约数--相减法
void maxCommonDivisor_sub()
{
	int x, y, a, b;
	printf("please input x, y\n");
	scanf_s("%d, %d", &x, &y);
	a = x;
	b = y;
	while (a != b)
	{
		if (a > b)
			a = a - b;
		else
			b = b - a;
	}
	printf("x=%d,y=%d->%d,%d\n", x, y, a, x * y / a);
}
//sinx 在[0,1]上的积分
void int_sinx()
{
	double a, b, s, h;
	int n = 150, i;
	a = 0;
	b = 1;
	s = 0;
	h = (b - a) / n;
	for (i = 1; i < n; i++)
		s = s + sin(a + i * h);
	s = h * ((sin(a) + sin(b)) / 2 + s);
	printf("s=%1f\n", s);
}
//不进行推导
void int_sinx_ori()
{
	double a, b, s, h;
	int n = 150, i;
	a = 0;
	b = 1;
	s = 0;
	h = (b - a) / n;
	for (i = 1; i <= n; i++)
		s = s + sin(a + (i - 1) * h) + sin(a + i * h);

	s = s * h / 2;
	printf("s=%1f\n", s);
}
//斐波那契数列
void fibonacci()
{
	long f1, f2;
	int i;
	f1 = f2 = 1;
	printf("%10ld%10ld", f1, f2);
	for (i = 2; i <= 1000; i++)
	{
		f1 = f1 + f2;
		f2 = f2 + f1;
		printf("%10ld%10ld", f1, f2);
		if (i % 2 == 0)
			printf("\n");
	}
}

//迭代法计算平方根
void sqrt_loop()
{
	double x0, x1, a, eps = 1.e-5;
	do
	{
		printf("please input a number(>0):");
		scanf_s("%lf", &a);
	} while (a < 0);
	x0 = a / 2;
	x1 = 0.5 * (x0 + a / x0);
	while (fabs(x1 - x0) >= eps)
	{
		x0 = x1;
		x1 = 0.5 * (x0 + a / x0);
	}
	printf("sqrt(%f)=%f\n", a, x1);
}
//枚举法
void seekSum12()
{
	int i, j, k, m, n = 0;
	for (i = 1; i < 10; i++)
		for (j = 1; j < 10; j++)
			for (k = 1; k < 10; k++)
				for (m = 1; m < 10; m++)
				{
					if (i == j || i == k || i == m || j == k || j == m || k == m)
						continue;
					if (i + j + k + m != 12)
						continue;
					n++;
					printf("{%d,%d,%d,%d}", i, j, k, m);
					if (n % 6 == 0)
						printf("\n");
				}
}

//小写转大写
void transToCap()
{
	char ch;
	ch = getchar();
	while (ch != '#')
	{
		ch = ch >= 'a' && ch <= 'z' ? ch - 32 : ch;
		putchar(ch);
		ch = getchar();
	}
}
//数列求和
void sumBang()
{
	int a = 1, s = 0, k = 1, an;
	for (int i = 0; i <= 50; i++)
	{
		an = k * (a + 2 * i);
		printf("an=%d\n", an);
		s = s + an;
		k = -k;
	}
	printf("s=%d", s);
}

//递推数列
void X_seq()
{
	int x0, x1, x2, xn;
	int index = 0, index_cur = 4;
	x0 = 1;
	x1 = 2;
	x2 = 3;
	// do{
	// printf("Please input index number:\n");
	// scanf_s("%d",&index);
	// }while(index<0);
	// if(index==1)

	for (int i = 3; i <= index; i++)
	{
		x0 = x0 + x1 + x2; //x3
		x1 = x1 + x2 + x0; //x4
		x2 = x2 + x0 + x1; //x5
		printf("x%d=%d, x%d=%d, x%d=%d\n", i, x0, i + 1, x1, i + 2, x2);
	}
}
//制造测试数据大文件
int makeTestDataFile()
{
	FILE *output_file;
	fopen_s(&output_file, "D://data_check//test_data1.dat", "wb");
	char zeros[1] = {0x00};
	//写入12行00，每行8字节
	for (int i = 0; i < 96; i++)
		fwrite(zeros, sizeof(char), 1, output_file);
	//写入填充数据
	char dummy[8] = {0x02, 0x09, 0x03, 0xa6, 0x02, 0x09, 0x03, 0xa6};
	//for (int i = 0; i<3; i++) fwrite(dummy, sizeof(char), 8, output_file);

	//写入帧头
	char frameHead[8] = {0x5a, 0x5a, 0x5a, 0x5a, 0xa5, 0xa5, 0xa5, 0xa5};
	fwrite(frameHead, sizeof(char), 8, output_file);
	//写入内容，32768*2 + 96 bytes
	char content[4] = {0x0, 0x0, 0x0, 0x0};
	char buf[4];

	static char data_buf[d_size];
	int k = 0;
	//int content = 0x0;
	printf("prcessing...\n");
	//4*5GB
	for (int t = 0; t < 8 * 6; t++)
	{
		for (int i = 0; i < d_size - 3; i += 4)
		{
			//content = content + 1;
			//_itoa_s(k, buf, 10);
			buf[0] = k & 0xff;
			buf[1] = k >> 8 & 0xff;
			buf[2] = k >> 16 & 0xff;
			buf[3] = k >> 24 & 0xff;
			k++;
			data_buf[i] = buf[0];
			data_buf[i + 1] = buf[1];
			data_buf[i + 2] = buf[2];
			data_buf[i + 3] = buf[3];
		}
		fwrite(data_buf, sizeof(char), d_size, output_file);
	}

	fclose(output_file);
	printf("Done.\n");
	return 0;
}

//逆序排列
void reverseSequence()
{
	int a[5], k, i, j, t;
	for (i = 0; i < 5; i++)
	{
		scanf_s("%d", &a[i]);
		printf("%4d", a[i]);
	}
	printf("\n");
	k = 5 / 2 - 1;
	for (i = 0; i <= k; i++) //逆序操作
	{
		j = 5 - i - 1;
		t = a[j];
		a[j] = a[i];
		a[i] = t;
	}
	for (i = 0; i < 5; i++)
	{
		printf("%4d", a[i]);
	}
}
//冒泡排序
#define N 5
void bubbleSeq()
{
	int i, j, m, a[N];
	int cnt = N;
	printf("please input %d numbers:\n", cnt);
	for (i = 0; i < N; i++)
	{
		scanf_s("%d", &a[i]);
	}
	for (j = 1; j <= N - 1; j++)
	{
		for (i = 0; i < N - j; i++)
		{
			if (a[i] < a[i + 1])
			{
				m = a[i];
				a[i] = a[i + 1];
				a[i + 1] = m;
			}
		}
	}
	for (i = 0; i < N; i++)
	{
		printf("%5d", a[i]);
	}
}
//改进的冒泡排序
//避免排序完成后继续进行比较
void bubbleSeq2()
{
	int i, j, m, a[N], end = 0;
	int cnt = N;
	printf("please input %d numbers:\n", cnt);
	for (i = 0; i < N && !end; i++)
	{
		scanf_s("%d", &a[i]);
	}
	for (j = 1; j <= N - 1; j++)
	{
		end = 1;
		for (i = 0; i < N - j; i++)
		{
			if (a[i] < a[i + 1])
			{
				m = a[i];
				a[i] = a[i + 1];
				a[i + 1] = m;
				end = 0; //发生交换，需要继续排序
			}
		}
	}
	for (i = 0; i < N; i++)
	{
		printf("%5d", a[i]);
	}
}
//选择法排序
void chooseSeq()
{
	int i, j, m, a[N], p;
	int cnt = N;
	printf("please input %d numbers:\n", cnt);
	for (i = 0; i < N; i++)
	{
		scanf_s("%d", &a[i]);
	}

	for (i = 0; i < N - 1; i++) //n-1轮处理
	{
		p = i;
		for (j = i + 1; j < N; j++)
		{
			//确定本轮的最小值的下标p
			if (a[p] > a[j])
				p = j;
		}
		if (p != i)
		{
			m = a[p];
			a[p] = a[i];
			a[i] = m;
		}
	}
	for (i = 0; i < N; i++)
	{
		printf("%5d", a[i]);
	}
}

//C语言有字符串常亮，却没有字符串变量，
//使用字符数组来保存字符串
//字符串数组初始化
void initCharArry()
{
	/*	
	//逐个字符初始化
	char a[6]={'C','h','i','n','a','\0'};

	//字符串常亮初始化
	char b[6]={"China"};
	char c[6]="China"; //省略大括号
	char d[] ="China";//省略数组长度
*/
	char a[10] = "China2000", b[3] = "12", c = 'G';
	printf("%c\n", a[3]);
	printf("%s\n", a);
	printf("%s\n", b);
}

//字符串IO
void stringIO()
{
	char str[100];
	char msg[] = "please input string and Press ENTER ";
	puts(msg);
	gets_s(str);
	puts(str);
}
//复制字符串
void copyString()
{
	char s1[80], s2[80];
	int i;
	printf("please input string s2:\n");
	gets_s(s2);
	for (i = 0; s2[i] != '\0'; i++)
	{
		s1[i] = s2[i];
	}
	s1[i] = '\0';
	puts(s1);
}
//求字符串长度
void lenString()
{
	char s1[80];
	int i;
	printf("please input string s1:\n");
	gets_s(s1);
	i = 0;
	while (s1[i] != '\0')
		i++;
	printf("len=%d\n", i);
}

void copyString2()
{
	char a[6] = "China", b[] = "123";
	strcpy_s(a, b);
	strcpy_s(b, "ABC");
	puts(a);
	puts(b);
}

//求多个字符串中长度最小的一个
void minLenString()
{
	char s1[80], min[80];
	int k, len;
	printf("Input string:\n");
	gets_s(s1);
	strcpy_s(min, s1);
	len = strlen(min);
	gets_s(s1);
	do
	{
		k = strlen(s1);
		if (k < len)
		{
			len = k;
			strcpy_s(min, s1);
		}
		gets_s(s1);
	} while (s1[0] != '\0');
	printf("len=%d,min=%s\n", len, min);
}
//字符串连接
void catString()
{
	char s1[10] = "China", s2[] = "abc";
	strcat_s(s1, s2);
	puts(s1);
}

//程序实现的字符串连接
void catString2()
{
	char s1[80], s2[80];
	int i, k;
	printf("please input s1 and s2:\n");
	gets_s(s1);
	gets_s(s2);
	i = 0;
	while (s1[i] != '\0')
		i++;
	k = 0;
	while (s2[k] != '\0')
	{
		s1[i] = s2[k];
		i++;
		k++;
	}
	s1[i] = '\0';
	printf("s1=s1+s2=%s\n", s1);
}

//字符大小写转换
void testTOLower_TOUpper()
{
	char a[15] = "china2000";
	char b[] = "ADB";
	_strlwr_s(b);
	_strupr_s(a);
	puts(a);
	puts(b);
}

//二维数组初始化
void matrixArry_init()
{
	//分行初始化
	//a[0][0]=1; a[0][1]=2; a[0][2]=3;
	int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
	//不分行初始化
	int b[2][3] = {1, 2, 3, 4, 5, 6};
}

//生成矩阵

void genMatrix()
{
	int i, j, k, a[N][N];
	k = 2;
	for (i = 0; i < N; i++)
		for (j = 0; j < N; j++)
			if (j <= i)
				a[i][j] = 1; //下三角元素，对角线
			else
				a[i][j] = k++; //上三角元素
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < N; j++)
			printf("%4d", a[i][j]);
		printf("\n");
	}
}

//矩阵行列互换
#define N2 4
void matrixTransposition()
{
	int i, j, k, a[N2][N2], b[N2][N2];
	for (i = 0; i < N2; i++)
		for (j = 0; j < N2; j++)
			scanf_s("%d", &a[i][j]);
	printf("A array is:\n");
	for (i = 0; i < N2; i++)
	{
		for (j = 0; j < N2; j++)
			printf("% -4d", a[i][j]);
		printf("\n");
	}
	for (i = 0; i < N2; i++)
		for (j = 0; j < N2; j++)
			b[j][i] = a[i][j];
	printf("B array:\n");

	for (i = 0; i < N2; i++)
	{
		for (j = 0; j < N2; j++)
			printf("% -4d", b[i][j]);
		printf("\n");
	}
}
//学生成绩平均值计算
void studentScore()
{
	int i, j;
	float a[N][5];
	for (i = 0; i < N; i++)
		for (j = 0; j < 4; j++)
			scanf_s("%f", &a[i][j]);
	for (i = 0; i < N; i++)
	{
		a[i][4] = 0;
		for (j = 1; j < 4; j++)
			a[i][4] += a[i][j];
		a[i][4] /= 3;
	}

	for (i = 0; i < N; i++)
	{
		printf("%-4.0f", a[i][0]);
		for (j = 0; j < 5; j++)
			printf("%-6.1f", a[i][j]);
		printf("\n");
	}
}
//二维字符数组
void twoDimensionCharArry()
{
	char a[3][8] = {"str1", "str2", "str3"};
	char b[][6] = {"s1", "st2", "str3"};
	int i;
	for (i = 0; i < 3; i++)
	{
		//按行输出
		printf("%s\n", a[i]);
	}
	for (i = 0; i < 3; i++)
	{
		//输出字符
		printf("%c\n", a[i][i]);
	}
	for (i = 0; i < 3; i++)
	{
		//某个位置开始的字符串，
		//注意使用了取地址运算
		printf("%s\n", &a[i][i]);
	}
}

//统计投票
//用二维字符数组保存人名
void tongJiTouPiao()
{
	char s[3][10], k[10];
	int b[3], i, j;
	for (i = 0; i < 3; i++)
	{
		gets_s(s[i]);
		b[i] = 0;
	}
	printf("输入候选人姓名\n");
	for (i = 0; i < 10; i++)
	{
		gets_s(k);
		for (j = 0; j < 3; j++)
			if (strcmp(s[j], k) == 0)
			{
				b[j]++;
				break;
			}
	}

	for (i = 0; i < 3; i++)
		printf("%10s:%5d\n", s[i], b[i]);
}

//统计整数的个数
void tongJiZhengShu()
{
	int i, j, k, a[100], b[10];
	k = 0;
	printf("input a integer(0--9), end with -1\n");
	scanf_s("%d", &j);
	while (j >= 0 && j <= 9)
	{
		a[k] = j;
		k++;
		scanf_s("%d", &j);
	}
	for (i = 0; i < 10; i++)
		b[i] = 0;
	for (i = 0; i < k; i++)
		b[a[i]] += 1;
	for (i = 0; i < 10; i++)
		printf("%d:%d\n", i, b[i]);
}

//随机数与有序数组
void randomAndSortedArry()
{
	int i, j, k, t, n, a[11];
	n = 10;
	printf("gen %d 2 number, then consist arry\n", n);
	for (i = 0; i < 10; i++)
	{
		a[i] = rand() % 90 + 10; //10,99的随机数
		printf("%4d", a[i]);
	}
	printf("\n");
	//选择法排序
	for (i = 0; i < 10 - 1; i++)
	{
		k = i;
		for (j = i + 1; j < n; j++)
			if (a[k] > a[j])
				k = j;
		if (k != i)
		{
			t = a[k];
			a[k] = a[i];
			a[i] = t;
		}
	}
	printf("sorted array from min to max:\n");
	for (k = 0; k < n; k++)
		printf("%4d", a[k]);
	printf("\n please input a number to insert:\n");
	scanf_s("%d", &k);
	for (i = 0; i < 10; i++) //寻找插入位置
		if (k < a[i])
			break;
	for (j = n; j > i; j--) //之后的元素都后移一个位置
		a[j] = a[j - 1];
	a[i] = k; //插入元素
	n += 1;
	printf("\n arry after insert:\n");
	for (i = 0; i < n; i++)
		printf("%4d", a[i]);
	//删除元素
	printf("\n index of the element to delete:\n");
	scanf_s("%d", &k);
	for (j = k; j < n - 1; j++) //前移一个位置
		a[j] = a[j + 1];
	n -= 1;
	printf("\narry after delete\n");
	for (i = 0; i < n; i++)
		printf("%4d", a[i]);
}

//矩阵乘法
void matrixMult()
{
	int i, j, k, t, a[3][2], b[2][3], c[3][3];
	printf("please input matrix A(3 row , 2 column) :");
	for (i = 0; i < 3; i++)
		for (j = 0; j < 2; j++)
			scanf_s("%d", &a[i][j]);
	printf("please input matrix B(2 row , 3 column) :");
	for (i = 0; i < 2; i++)
		for (j = 0; j < 3; j++)
			scanf_s("%d", &b[i][j]);

	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
		{
			t = 0;
			for (k = 0; k < 2; k++)
				t += a[i][k] * b[k][j];
			c[i][j] = t;
		}
	//输出C矩阵
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
			printf("%5d", c[i][j]);
		printf("\n");
	}
}

//查找矩阵
void searchMatrix()
{
	int i, j, k, t = 0, a[5][5];
	printf("gen 5*5 numbers to make array\n");
	for (i = 0; i < 5; i++)
	{
		for (j = 0; j < 5; j++)
		{
			a[i][j] = rand() % 90 + 10;
			printf("%4d", a[i][j]);
		}
		printf("\n");
	}

	printf("please input number to search:\n");
	scanf_s("%d", &k);
	for (i = 0; i < 5; i++)
	{
		for (j = 0; j < 5; j++)
		{
			if (a[i][j] == k)
			{
				printf("a[%d][%d]=%d\n", i, j, k);
				t = 1;
			}
		}
	}
	if (t != 1)
		printf("%d not found!\n", k);
}
//不使用strcmp的字符串比较
void stringCompare()
{
	char s1[80], s2[80];
	int i = 0, j;
	gets_s(s1);
	gets_s(s2);
	while (s1[i] && s2[i]) //'\0'的值是0x0
	{
		if (s1[i] != s2[i])
			break;
		i++;
	}
	j = s1[i] - s2[i];
	if (j > 0)
		printf("%s>%s\n", s1, s2);
	else if (j < 0)
		printf("%s<%s", s1, s2);
	else
		printf("%s=%s", s1, s2);
}
//判断一个字符串是否包含另一个字符串
void containString()
{
	char s1[80], s2[80];
	int i = 0, j, k, k1, k2, f;
	gets_s(s1);
	gets_s(s2);
	k1 = strlen(s1);
	k2 = strlen(s2);
	f = 0;
	while (i < k1 - k2 + 1 && !f)
	{
		j = 0;
		k = i;
		while (s2[j] && s1[k] == s2[j])
		{
			j++;
			k++;
		}
		if (s2[j] == '\0')
		{
			f = 1;
			break;
		}
		i++;
	}
	if (f == 1)
		printf("%s is in %s", s2, s1);
	else
		printf("%s is not in %s", s2, s1);
}

//5个字符串按照大小排序
void sortString()
{
	char s[5][80];
	int i, j, k, m, a[5];
	for (i = 0; i < 5; i++)
	{
		gets_s(s[i]);
		a[i] = i;
	}
	for (i = 0; i < 4; i++)
	{
		k = i;
		for (j = i + 1; j < 5; j++)
			if (strcmp(s[a[k]], s[a[j]]) > 0)
				k = j;

		if (k != i)
		{
			m = a[k];
			a[k] = a[i];
			a[i] = m;
		}
	}
	for (i = 0; i < 5; i++)
		printf("%-s\n", s[a[i]]);
}
//根据输入的数字输出星期
void weekGen()
{
	char week[7][9] = {"Sunday", "Monday", "Tuesday", "Wednsday", "Thursday", "Friday", "Saturday"};
	int i, j, k, a, n;
	do
	{
		printf("please input a number:\n");
		scanf_s("%d", &n);
	} while (n < 100 || n > 999);
	i = n / 100;
	j = n / 10 % 10;
	k = n % 10;
	a = (i + j + k) % 7;
	printf("\n %d->%d+%d+%d->week[%d]->%s\n", n, i, j, k, a, week[a]);
}
//============================
//编程习题

//1. 4x4矩阵两条对角线元素的和
void sumDiag_2()
{
	int a[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
	int i, j; //行列索引
	int sum = 0;
	for (i = 0; i < 4; i++)
		for (j = 0; j < 4; j++)
		{
			if (i == j || (i + j == 3))
				sum += a[i][j];
		}
	printf("The sum of the two diagonal is %d\n", sum);
}
//2. 按一定規則求平均值
void mean5()
{
	int a[40];
	int i, b, k;
	for (i = 0; i < 30; i++)
	{
		a[i] = (2 * (i + 1));
		printf("a[%d] is %d\n", i, a[i]);
	}
	//每5个求平均值
	k = 30;
	for (i = 0; i < 30 - 4; i += 5)
	{
		b = (a[i] + a[i + 1] + a[i + 2] + a[i + 3] + a[i + 4]) / 5;
		a[k] = b;
		k++;
	}
	for (i = 0; i < 36; i++)
	{

		printf("a[%d] is %d\n", i, a[i]);
	}
}
//3. 生成一个具有30个随机数的数组，并删除最大值，然后输出该数组
void array30_delMax()
{
	int a[30];
	int i;
	for (i = 0; i < 30; i++)
	{
		a[i] = rand() % 100;
		printf("a[%d] is %d\n", i, a[i]);
	}
	int max = 0, index;
	for (i = 0; i < 30; i++)
	{
		if (max < a[i])
		{
			max = a[i];
			index = i;
		}
	}
	printf("max is a[%d] is %d\n", index, a[index]);
	for (i = index; i < 30; i++)
	{
		a[i] = a[i + 1];
	}
	//输出
	for (i = 0; i < 30 - 1; i++)
	{

		printf("a[%d] is %d\n", i, a[i]);
	}
}

//函数
int foo(int x)
{
	return x * 2;
}

float foo(float x)
{
	return x * 3;
}

void drawHexagon()
{
	int m, n, i;
	void pt(int n, char ch);
	printf("Enter length:");
	scanf_s("%d", &n);
	for (i = n - 1; i >= -n + 1; i--)
	{
		m = (i > 0) ? i : -i;
		pt(m, ' ');
		if (i == n - 1 || i == -n + 1)
		{
			pt(n, '*');
			pt(1, '\n');
		}
		else
		{
			pt(1, '*');
			pt(3 * n - 2 * m - 4, ' ');
			pt(1, '*');
			pt(1, '\n');
		}
	}
}

void pt(int n, char ch)
{
	while (n-- > 0)
	{
		printf("%c", ch);
	}
}

void testArgs(int *p)
{
	*p = 89;
}
//数组名作为函数的参数
void func(char str[])
{
	printf("%s", str);
}

//二维数组名作为函数的参数
void showDayOfYear()
{
	static int day_tab[2][13] = {
		{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
		{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
	int y, m, d;
	scanf_s("%d%d%d", &y, &m, &d);
	printf("%d\n", day_of_year(day_tab, y, m, d));
}

int day_of_year(int d_tab[][13], int year, int month, int day)
{
	int i, j;
	i = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
	for (j = 1; j < month; j++)
		day += d_tab[i][j];
	return day;
}
//外部变量
void addone()
{
	x++;
	printf("add 1 to make %d\n", x);
}
void subone()
{
	x--;
	printf("substract 1 to make %d\n", x);
}

void add()
{
	y = 10 + x;
	x *= 2;
}
//静态变量
void add1()
{
	x+=2;
	y+=3;
	printf("in add1 x=%d\n", x);
}

void inc2()
{
	static int x =0;
	x++;
	printf("in inc2 x is %d\n",x);
}

//递归
int facto(int n)
{
	int r;
	if(n==0) r=1;
	else 	r=n*facto(n-1);
	return r;
}

double px(double x, int n)
{
	if(n==1) return x;
	else return (x*(1-px(x, n-1)));
}

void printn(int n)
{
	if(0<=n && n<=9)
	{
		printf("%d",n);
	}
	else
	{
		printf("%d",n%10);
		printn(n/10);
	}
}

void movedisc(unsigned n, char fromneedle, char toneedle, char usingneedle)
{
	if(n==1)
		printf("%2d-(%2d):%c ==>%c\n",++i,n,fromneedle, toneedle);
	else
	{
		movedisc(n - 1, fromneedle,  usingneedle, toneedle);
		printf("%2d-(%2d):%c ==>%c\n", ++i, n, fromneedle, toneedle);
		movedisc(n - 1, usingneedle, toneedle, fromneedle);

	}

}

//指针-swap
void swap2(int *px, int *py)
{
	int temp;
	temp = *px;
	*px = *py;
	*py = temp;
	printf("in swap x = %d,y=%d\n", *px,*py);
}

//函数返回指针
int *max(int *a, int *b)
{
	int *p;
	p = *a > *b ? a : b;
	return (p);
}